module KBEngine{
    export class Account extends KBEngine.Entity{
        constructor(){
			super();
            KBEngine.Event.fire("onLoginSuccessfully");
		}

        __init__() {
        }

        set_score() {
            if (PlayerModel.IsSelfFarm()) {
                PlayerModel.SetScore(this["score"]);
                CtrlManager.GetCtrl(CtrlNames.Player).SetScore();
            }
        }

        set_fieldNum() {
            if (PlayerModel.IsSelfFarm()) {
                FieldModel.SetFieldNum(this["fieldNum"]);
            }
        }

        set_fieldList() {
            if (PlayerModel.IsSelfFarm()) {
                FieldModel.SetFieldList(this["fieldList"]);
            }
        }

        set_weatherId() {
            if (PlayerModel.IsSelfFarm()) {
                WeatherModel.SetWeatherId(this["weatherId"]);
                CtrlManager.GetCtrl(CtrlNames.Field).SetWeather();
            }
        }

        set_mail_info_list(){
            if (PlayerModel.IsSelfFarm()) {
                CtrlManager.GetCtrl(CtrlNames.Mail).disBubble(true);
            }
        }

        setServerTime(serverTime:number) {
            Game.serverTime = serverTime;
            CtrlManager.GetCtrl(CtrlNames.Share).shareApp();
            FieldModel.InitStage();
            CtrlManager.GetCtrl(CtrlNames.Field).SetField();
            CtrlManager.GetCtrl(CtrlNames.Shield).SetShield();
            CtrlManager.GetCtrl(CtrlNames.Mail).setBubble();
            CtrlManager.GetCtrl(CtrlNames.Task).setBubble();
            CtrlManager.GetCtrl(CtrlNames.Task).setBubble();
        }

        onPlant(index:number, cropId:number) {
            if (PlayerModel.IsSelfFarm()) {
                CtrlManager.GetCtrl(CtrlNames.Field).OnPlant(index, cropId);
            }
        }

        onHarvest(index:number, getScore:number) {
            if (PlayerModel.IsSelfFarm()) {
                CtrlManager.GetCtrl(CtrlNames.Field).OnHarvest(index);
            }
        }

        onExpand(fieldNum:number) {
            if (PlayerModel.IsSelfFarm()) {
                CtrlManager.GetCtrl(CtrlNames.Field).OnExpand(fieldNum);
            }
        }

        onTaskFinish(id:number, type:number, stage:number){
            CtrlManager.GetCtrl(CtrlNames.Task).onTaskFinish(id, type, stage);
        }
        onTaskDailyActiveReceive(index:number){
            CtrlManager.GetCtrl(CtrlNames.Task).onTaskDailyActiveReceive(index);
        }

        addDisaster(weatherId:number, fieldIndexArray:any) {
            if (PlayerModel.IsSelfFarm()) {
                CtrlManager.GetCtrl(CtrlNames.Field).AddDisaster(weatherId, fieldIndexArray);
            }
        }

        clearAllDisaster() {
            if (PlayerModel.IsSelfFarm()) {
                CtrlManager.GetCtrl(CtrlNames.Field).ClearAllDisaster();
            }
        }

        onClearDisaster(index:number) {
            if (PlayerModel.IsSelfFarm()) {
                CtrlManager.GetCtrl(CtrlNames.Field).OnClearDisaster(index);
            }
        }

        //转盘抽奖
        turntableRsq(darw_id:number,darw_level:number,physical:number,textTime:number ,prizeMultiple:number ):void{
            CtrlManager.GetCtrl(CtrlNames.Darw).turntableRsq(darw_id, darw_level,physical, textTime,prizeMultiple);
        }
        physicalValueRsq(physical:number,textTime:number):void{
            CtrlManager.GetCtrl(CtrlNames.Darw).physicalValueRsq(physical, textTime);
        }
        setPhysicalValueRsq(physical:number):void{
             CtrlManager.GetCtrl(CtrlNames.Darw).setPhysicalValueRsq(physical);
        }

        //签到奖励
        signObtainRsq(signDay:number,type:number ):void{
            CtrlManager.GetCtrl(CtrlNames.Sign).signObtainRsq(signDay,type);
        }
        //获取签到表
        signTableRsq(weekNum:number,dayOfWeek:number,sizeSignNum:number,signWeek:Array<number>,signMonth:Array<number> ):void{
            CtrlManager.GetCtrl(CtrlNames.Sign).signTableRsq(weekNum, dayOfWeek,sizeSignNum,signWeek,signMonth);
        }
        //28天的四次奖励
        SignMonthPrize(cnt:number):void{
            CtrlManager.GetCtrl(CtrlNames.Sign).SignMonthPrize(cnt);
        }

        //使用道具
        onHaveProp(itemId, count, customArg){
            if (PlayerModel.IsSelfFarm()) {
                CtrlManager.GetCtrl(CtrlNames.Warehouse).onHaveProp(itemId, count, customArg);
            }
        }

        set_shieldIsOpen() {
            if (PlayerModel.IsSelfFarm()) {
                ShieldModel.SetIsOpen(this["shieldIsOpen"]);
            }
        }

        set_shieldInviteList() {
            ShieldModel.SetInviteList(this["shieldInviteList"]);
        }

        set_shieldEndTime(old_shieldEndTime:number) {
            if (PlayerModel.IsSelfFarm()) {
                ShieldModel.SetEndTime(this["shieldEndTime"]);
                if (ShieldModel.CheckStutus()) {
                    CtrlManager.GetCtrl(CtrlNames.Shield).SetShield();
                }
            }
        }

        //激活护盾
        onOpenShield() {
            if (PlayerModel.IsSelfFarm()) {
                ShieldModel.SetIsOpen(this["shieldIsOpen"]);
                CtrlManager.GetCtrl(CtrlNames.Shield).SetShield();
            }
        }

        //提示
        onPrompt(id:number) {
            Game.viewFarm.OnPrompt(id);
        }

        //进入好友农场
        onEenterFriendFarm(dbid:KBEngine.UINT64, fieldNum:number, fieldList:any, weatherId:number, 
            shieldIsOpen:number, shieldEndTime:number) {
            CtrlManager.GetCtrl(CtrlNames.Friend).EenterFriendFarm(dbid, fieldNum, fieldList, weatherId, 
                shieldIsOpen, shieldEndTime);
        }

        //获取好友基础信息
        GetFriendInfo(dbid:KBEngine.UINT64) : any {
            let friendCount : number = this["friendInfoList"].length;
            for (let index = 0; index < friendCount; index++) {
                let friendInfo = this["friendInfoList"][index]
                if (friendInfo.dbid.lo == dbid.lo && friendInfo.dbid.hi == dbid.hi) {
                    return friendInfo;
                }
            }
            return null;
        }

        //偷取成功,服务器通知
        stealSuccess(index:number, stealScore:number) {
            if (!PlayerModel.IsSelfFarm()) {
                Game.viewFarm.stealSuccess(index, stealScore);
            }
        }

        //好友农场数据更新 - 地块数量
        watchedUpdateFieldNum(dbid:KBEngine.UINT64, fieldNum:number) {
            if (!PlayerModel.IsSelfFarm() && PlayerModel.GetFriendDbid().toString() == dbid.toString()) {
                FieldModel.SetFieldNum(fieldNum);
                CtrlManager.GetCtrl(CtrlNames.Field).OnExpand(fieldNum);
            }
        }

        //好友农场数据更新 - 地块数据
        watchedUpdateFieldList(dbid:KBEngine.UINT64, fieldList:any) {
            if (!PlayerModel.IsSelfFarm() && PlayerModel.GetFriendDbid().toString() == dbid.toString()) {
                FieldModel.SetFieldList(fieldList);
            }
        }

        //好友农场数据更新 - 天气
        watchedUpdateWeather(dbid:KBEngine.UINT64, weatherId:number) {
            if (!PlayerModel.IsSelfFarm() && PlayerModel.GetFriendDbid().toString() == dbid.toString()) {
                WeatherModel.SetWeatherId(weatherId);
                CtrlManager.GetCtrl(CtrlNames.Field).SetWeather();
            }
        }

        //好友种植
        watchedPlant(dbid:KBEngine.UINT64, index:number, cropId:number) {
            if (!PlayerModel.IsSelfFarm() && PlayerModel.GetFriendDbid().toString() == dbid.toString()) {
                CtrlManager.GetCtrl(CtrlNames.Field).OnPlant(index, cropId);
            }
        }

        //好友收获
        watchedHarvest(dbid:KBEngine.UINT64, index:number) {
            if (!PlayerModel.IsSelfFarm() && PlayerModel.GetFriendDbid().toString() == dbid.toString()) {
                CtrlManager.GetCtrl(CtrlNames.Field).OnHarvest(index);
            }
        }

        //好友添加灾害
        watchedAddDisaster(dbid:KBEngine.UINT64, weatherId:number, fieldIndexArray:any) {
            if (!PlayerModel.IsSelfFarm() && PlayerModel.GetFriendDbid().toString() == dbid.toString()) {
                CtrlManager.GetCtrl(CtrlNames.Field).AddDisaster(weatherId, fieldIndexArray);
            }
        }

        //好友清除所有灾害
        watchedClearAllDisaster(dbid:KBEngine.UINT64) {
            if (!PlayerModel.IsSelfFarm() && PlayerModel.GetFriendDbid().toString() == dbid.toString()) {
                CtrlManager.GetCtrl(CtrlNames.Field).ClearAllDisaster();
            }
        }

        //好友清除指定地块灾害
        watchedClearDisaster(dbid:KBEngine.UINT64, index:number) {
            if (!PlayerModel.IsSelfFarm() && PlayerModel.GetFriendDbid().toString() == dbid.toString()) {
                CtrlManager.GetCtrl(CtrlNames.Field).OnClearDisaster(index);
            }
        }

        //好友激活护盾
        watchedOpenShield(dbid:KBEngine.UINT64) {
            if (!PlayerModel.IsSelfFarm() && PlayerModel.GetFriendDbid().toString() == dbid.toString()) {
                ShieldModel.SetIsOpen(1);
                CtrlManager.GetCtrl(CtrlNames.Shield).SetShield();
            }
        }

        //好友增加护盾时间
        watchedAddShieldTime(dbid:KBEngine.UINT64, shieldEndTime:number) {
            if (!PlayerModel.IsSelfFarm() && PlayerModel.GetFriendDbid().toString() == dbid.toString()) {
                ShieldModel.SetEndTime(shieldEndTime);
                CtrlManager.GetCtrl(CtrlNames.Shield).SetShield();
            }
        }

        //点击分享链接回调,服务器调用
        onShareClick(dbid:string, shareType:string){
            CtrlManager.GetCtrl(CtrlNames.Share).onShareClick(dbid, shareType);
        }
    }
}